The Artima Developer Community
Sponsored Link

Java Answers Forum
how to program this?

3 replies on 1 page. Most recent reply: Feb 1, 2006 7:10 PM by Marlon Cortez

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
casper newbie

Posts: 7
Nickname: casper3
Registered: Jan, 2006

how to program this? Posted: Jan 28, 2006 6:13 AM
Reply to this message Reply
Advertisement
gud day to you all............
My name is Casper and i'm new to java. I only started learning java just a month ago...
And my problem is that our teacher want us to program the following problems. But i dont know how to make it.... could anyone help me with my problems PLEASE ??????

a. Write an Application that displays a box, an oval, an arrow and a diamond using asterisks (*).

b. Write an application that determines and display a group of integers (maximum 5 groups of integers and prints the largest and smallest integers in the group.
Output:
Group of integers: 4 30 -5 0 10
Largest: 30
Smallest: -5

OUR TEACHER TOLD US TO PROGRAM IT IN A VERY SIMPLE WAY...
PLEASE HELP ME....... GOD BLESS TO YOU........


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: how to program this? Posted: Jan 30, 2006 12:47 AM
Reply to this message Reply
> gud day to you all............
> My name is Casper and i'm new to java. I only
> I only started learning java just a month ago...
> And my problem is that our teacher want us to
> t us to program the following problems. But i dont know
> how to make it.... could anyone help me with my problems
> PLEASE ??????
>
> a. Write an Application that displays a box, an oval, an
> arrow and a diamond using asterisks (*).
>
use for loops and System.out.print()
//  Not tested but this should print you a box of
//  length 4
for(int i = 0; i < 8; i++){ 
    if(i == 4){
       for(int j = 0; j < 4; j++){
           System.out.print("\n*");
           for(int k = 0; k < 3; k++){
               if(k == 2){
                   System.out.println("*\n");
                   continue;
               }
               System.out.print(" ");
           }
       }
    }else{
       System.out.print("*");
    }
}

Mess around with the above code for the arrow and the oval.

> b. Write an application that determines and display a
> group of integers (maximum 5 groups of integers and prints
> the largest and smallest integers in the group.
> Output:
> Group of integers: 4 30 -5 0 10
> Largest: 30
> Smallest: -5
These are simple logic statements (if/else).
algorithm:
store your numbers in an array.
int max_num = array[0];
for(int i = 0; i < array.length; i++){
    if(max_num < array[i]){
        max_num = array[i];
    }
    //  By the end of the iteration, max_num will hold
    //  the largest number in the array.
}

do the inverse for the smallest number.
>
> OUR TEACHER TOLD US TO PROGRAM IT IN A VERY SIMPLE
> LE WAY...
> PLEASE HELP ME....... GOD BLESS TO YOU........

Marlon Cortez

Posts: 7
Nickname: cotz
Registered: Feb, 2006

how to program this? Posted: Feb 1, 2006 6:46 PM
Reply to this message Reply
public class IfElseDemo {
public static void main(String[] args) {

int testscore = 76;
char grade;

if (testscore >= 90) {
grade = 'A';
} else if (testscore >= 80) {
grade = 'B';
} else if (testscore >= 70) {
grade = 'C';
} else if (testscore >= 60) {
grade = 'D';
} else {
grade = 'F';
}
System.out.println("Grade = " + grade);
}
}
This is the output from the program.
Grade = C

what if.. i want to put myself a testscore and not by default as it was in above testscore = 76;... how change it?
tnx

Marlon Cortez

Posts: 7
Nickname: cotz
Registered: Feb, 2006

how to program this? Posted: Feb 1, 2006 7:10 PM
Reply to this message Reply
* ********** * **********
** ********* ** *********
*** ******** *** ********
**** ******* **** *******
***** ****** ***** ******
****** ***** ****** *****
******* **** ******* ****
******** *** ******** ***
********* ** ********* **
********** * ********** *



hoq program this using FOR LOOP or NEXT LOOP... TNX

Flat View: This topic has 3 replies on 1 page
Topic: JAVA NEWBIE Previous Topic   Next Topic Topic: JNI Calling Signature Problem. Please Help me out

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use