Thread: help with these 4 more problems please.

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    help with these 4 more problems please.

    Code:
    1. Given an  int variable  k that has already been declared, use a  for loop to print a single line consisting of 97 asterisks. Use no variables other than  k . 
    
    ans: but don't work.
    for(k=0;k<97;k++)
    System.out.print(“*”);
    
    2. Given an  int variable  n that has already been declared and initialized to a positive value, and another  int variable  j that has already been declared, use a  for loop to print a single line consisting of  n asterisks. Thus if  n contains 5, five asterisks will be printed. Use no variables other than  n and  j . 
    
    ans: but don't work.
    for(j=0;j<5;j++)
    System.out.print(“*”);
    
    3. Given an  int variable  k that has already been declared, use a  while loop to print a single line consisting of 88 asterisks. Use no variables other than  k .
    
    ans: but don't work
    k=0; 
    while(k<88)
    {
    System.out.print(“*”);
     k++;
    }
    
    4. Given an  int variable  n that has already been declared and initialized to a positive value, use a  while loop to print a single line consisting of  n asterisks. Use no variables other than  n . 
    
    ans: but don't work
    while(n>0)
    {
    System.out.print(“*”);
    n--;
    }

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    I don't know what language "System.out.print" is from, but it's not from C. Try printf("*");

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    That is Java code, not C. It doesn't work because you are programming in the wrong language.
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Location
    USA
    Posts
    63
    its java code

    if you want to print something in c use"printf();"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM