There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
audio avg avg 8 blue screen brand new codec computer control panel conversion crash delete personal data desktop display dos driver duplicate dvd error error message excel explorer file firefox game graphics hardware hijackthis log install installation internet itunes javascript lan laptop macro malware msn music network outlook outlook 2003 outlook express php problem random rundll32 security seo sound sp3 spyware switch tag cloud tech trojan usb video virtumonde virus vista visual basic vundo wallpaper windows windows vista windows xp wireless word xp sp3 youtube
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Jafva help!


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
bootsiebella's Avatar
Junior Member with 12 posts.
 
Join Date: Mar 2008
09-May-2008, 09:33 PM #1
Jafva help!
reads in two integers and determines and prints if the first is a multiple of the second using the modulus operator. Is this correct algorithm below

public static void main(String[] args) {
int in = 10;
passMethod(in);

// print x to see if its value has changed
System.out.println("After invoking passMethod, in = " + in);
}
public static void passMethod(int p) {
p = 20;
}
}


calculates the squares and cubes of the numbers from 0 to 10
Did I do this Algorithm correct if anyone can understand it?

Step1: Input or variable declaration

Step2: //Output
System.out.printf( "number\tsquare\tcube\n");
System.out.printf( "%d\t%d\t%d\n", number , square, cube);

Step3: // Processing
number =number + 1;
square = number*number;
cube = number*number*number;

Step4: //Output
System.out.printf( "%d\t%d\t%d\n", number, square, cube);

Step5: Repeat Step 3
Step6: Repeat Step 4
Step7: Repeat Step 3
Step8: Repeat Step 4
Step9: Repeat Step 3
Step10: Repeat Step 4
Step11: Repeat Step 3
Step12: Repeat Step 4
Step13: Repeat Step 3
Step14: Repeat Step 4
STep15: Repeat Step 3
STep16: Repeat Step 4
STep17: Repeat Step 3
STep18: Repeat Step 4
STep19: Repeat Step 3
STep20: Repeat Step 4
STep21: Repeat Step 3
STep22: Repeat Step 4
Step23: Stop
Chicon's Avatar
Computer Specs
Distinguished Member with 6,215 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.58" E
Experience: Intermediate
10-May-2008, 02:50 AM #2
Quote:
reads in two integers and determines and prints if the first is a multiple of the second using the modulus operator. Is this correct algorithm below
Not exactly !
You should have something like this :
Code:

    int x = some value;
    int y = some value;
    int r = y % x;
    if (r == 0) {
        System.out.println(y + " is a multiple of " + x);
    }
For the second part, just use a for statement :
Code:

    for (int x = 0; x < 11; x++) {
       System.out.printf(""%d\t%d\t%d\n", x, (x*x), (x*x*x));
    }
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:24 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.