• Post Reply Bookmark Topic Watch Topic
  • New Topic

program produces no output  RSS feed

 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello, can someone please help me with this code above ? I have tried to solve it for a while, but im just not sure what to do :/ Thank you.
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

We do not give out complete solutions. What happens if you call that method?
 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing happens, I need to get it to post 9 times line "Life is not fair - get used to it.". One thing i tried doing was
package com.javarush.test.level01.lesson08.task01;

import java.lang.String;

/* Life is not fair
Write a program that displays 9 times: «Life is not fair - get used to it.».
*/
public class Solution
{
public static void main(String[] args)
{
String s= "Life is not fair - get used to it.";
}

public static void print3Times(String s)
{
System.out.println(s);
System.out.println(s);
System.out.println(s);
}
}
But it doesnt show any text or something. I also tried adding that line to print3Times(String s=line).
 
Henry Wong
author
Sheriff
Posts: 23291
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awectga cawetc wrote:
But it doesnt show any text or something. I also tried adding that line to print3Times(String s=line).


Adding a method that prints out three times isn't enough. The method that you added has to be actually used (meaning executed). Can you show us where you actually call the method that you added?

Henry
 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.lang.String;

/* Life is not fair
Write a program that displays 9 times: «Life is not fair - get used to it.».
*/
public class Solution
{
public static void main(String[] args)
{
String s= "Life is not fair - get used to it.";
}

public static void print3Times(String s)
{
System.out.println(s);
System.out.println(s);
System.out.println(s);
}
}
There I guess. This is an exercise from a tutorial page.
 
Henry Wong
author
Sheriff
Posts: 23291
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That line is for a String declaration and initialization. There is no method call at that location.

Henry
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you have been told to use that package name, delete the package name which is providing you with no benefit and may make the code more difficult to compile.
Remove the import of String because that is unnecessary and has not effect.
I shall change your post to black text throughout because the pink text is very difficult to read.
You have a start (), declaring the String s. But you need to use it before anything will happen.
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arquon Gimb wrote: . . . This is an exercise from a tutorial page.
You must tell us where such code comes from, to avoid copyright problems. What else does it say on that tutorial page?
 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Arquon Gimb wrote: . . . This is an exercise from a tutorial page.
You must tell us where such code comes from, to avoid copyright problems. What else does it say on that tutorial page?

This is from https://javarush.net/login.html and theres no more info about this exercise.
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Now, reading what we have told you about the app, you appear to have the text to print and you have a method which takes text as its argument. Have you worked out how to put the two together?

Please use the code button; you have already seen how much better it makes the code look
 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is one of the similiar exercises

I just cant figure it out how do I get it to print 2 lines 2 times. I tried declaring String s in //add your code here; line, but no luck. Also tried doing it like :
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We seem to be going round in circles. Does the tutorial tell you how to call a method? If you can't get it to print two twice can you get it to print once?

Hint: all the code you have shown so far has been correct. None of it has been complete. Don't change correct code. Except that you should remove the package names.
 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:We seem to be going round in circles. Does the tutorial tell you how to call a method? If you can't get it to print two twice can you get it to print once?

Hint: all the code you have shown so far has been correct. None of it has been complete. Don't change correct code. Except that you should remove the package names.

I dont know how to use

this command at all. And if you have some time, could you check this exercise ? Its in Level 1, exercise 8.
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, because I am not logged on to that tutorial.
What did the tutorial say about calling methods? Have you seen the Java™ Tutorials?
 
Arquon Gimb
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its quick to login, just click create secret key and you can log in. Lesson did mention String getName() {} at the end of it. I guess i should use this somewhere ?
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not logging in. Ignore what they said about getName().
 
salvin francis
Saloon Keeper
Posts: 1644
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arquon,

You may want to read this:
https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
and then this:
https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe after 1½ weeks the OP has given up.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!